import 'dart:async';

import 'package:tiktokadult/config/config.dart';
import 'package:tiktokadult/hj_utils/light_model.dart';

//书架的new标志
const _KEY_ACG_RECORD = "_key_acg_book_record${Config.DEBUG}";
const _MAX_CACHE_COUNT = 300;

// 本地有声小说记录
class LocalACGStore {
  static LocalACGStore? _instance;
  factory LocalACGStore() {
    _instance ??= LocalACGStore._();
    return _instance!;
  }
  LocalACGStore._() {}

  //保存漫画记录
  Future saveBookNewRecord(String? vid, int? episode) async {
    if (vid == null || null == episode) return;
    lightKV.setInt(vid, episode);
  }

  //获取漫画观看记录
  Future<int> getBookNewRecord(String? vid) async {
    if (vid == null) return 0;
    int? episode = await lightKV.getInt(vid);
    episode ??= 0;
    return episode;
  }

  //保存漫画记录,某部漫画 某子集 第某
  Future saveComicPlayRecord(String? mid, String? id, int? index) async {
    if (mid == null || null == id || index == null) return;
    lightKV.setInt(mid + id, index);
  }

  //保存漫画记录,某部漫画 某子集 第某
  Future<int> getComicPlayRecord(String? mid, String? id) async {
    if (mid == null || null == id) return 0;
    int? index = await lightKV.getInt(mid + id);
    return index ?? 0;
  }
}
